/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {number[]} preorder
 * @param {number[]} inorder
 * @return {TreeNode}
 */
 var buildTree = function(preorder, inorder) {
    if(preorder === null) return null
    let nodeVal = preorder.shift()
    let inIndex = inorder.indexOf(nodeVal)
    let node = new TreeNode(nodeVal,null,null)
    node.left = buildTree(preorder.slice(0,inIndex),inorder.slice(0,inIndex))
    node.right = buildTree(preorder.slice(inIndex),inorder.slice(inIndex + 1))
    return node
};